<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python高级 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>import导入模块 | python高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../day11/04.review.html" />
    
    
    <link rel="prev" href="../day11/02.copy.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="1.3"
        data-chapter-title="import导入模块"
        data-filepath="day11/03.import.md"
        data-basepath=".."
        data-revision="Wed Sep 26 2018 22:46:13 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Python高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="day11/00.readme.html">
            
                
                    <a href="../day11/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Python语法高级专题1
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="day11/01.GIL.html">
            
                
                    <a href="../day11/01.GIL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        GIL问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="day11/02.copy.html">
            
                
                    <a href="../day11/02.copy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        赋值-浅拷贝-深拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.3" data-path="day11/03.import.html">
            
                
                    <a href="../day11/03.import.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        import导入模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="day11/04.review.html">
            
                
                    <a href="../day11/04.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="day12/00.readme.html">
            
                
                    <a href="../day12/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Python语法高级专题2
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="day12/01.mro.html">
            
                
                    <a href="../day12/01.mro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        多继承和MRO顺序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="day12/02.property.html">
            
                
                    <a href="../day12/02.property.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        property属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="day12/03.magic.html">
            
                
                    <a href="../day12/03.magic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        魔法属性和方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="day12/04.with.html">
            
                
                    <a href="../day12/04.with.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        with管理上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="day12/05.review.html">
            
                
                    <a href="../day12/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="day13/00.readme.html">
            
                
                    <a href="../day13/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Python语法之装饰器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="day13/01.closure.html">
            
                
                    <a href="../day13/01.closure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        闭包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="day13/02.decorator.html">
            
                
                    <a href="../day13/02.decorator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="day13/03.review.html">
            
                
                    <a href="../day13/03.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="day14/00.readme.html">
            
                
                    <a href="../day14/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        MySQL数据库基本操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="day14/01.数据库概述.html">
            
                
                    <a href="../day14/01.数据库概述.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        数据库概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="day14/02.数据类型和约束.html">
            
                
                    <a href="../day14/02.数据类型和约束.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        数据完整性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="day14/03.Navicat.html">
            
                
                    <a href="../day14/03.Navicat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        图形化客户端Navicat
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="day14/04.命令行客户端.html">
            
                
                    <a href="../day14/04.命令行客户端.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        命令行客户端SQL的使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="day14/05.sql_con.html">
            
                
                    <a href="../day14/05.sql_con.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.1.</b>
                        
                        登录和退出数据库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="day14/07.sql_table_struct.html">
            
                
                    <a href="../day14/07.sql_table_struct.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.2.</b>
                        
                        表结构的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.3" data-path="day14/06.sql_database.html">
            
                
                    <a href="../day14/06.sql_database.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.3.</b>
                        
                        数据库的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.4" data-path="day14/08.表数据操作.html">
            
                
                    <a href="../day14/08.表数据操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.4.</b>
                        
                        表数据的操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="day14/09.review.html">
            
                
                    <a href="../day14/09.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        知识总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="day15/00.readme.html">
            
                
                    <a href="../day15/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        MYSQL数据库进阶操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="day15/01.练习.html">
            
                
                    <a href="../day15/01.练习.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        练习强化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="day15/02.where条件.html">
            
                
                    <a href="../day15/02.where条件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        条件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="day15/03.排序查询.html">
            
                
                    <a href="../day15/03.排序查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="day15/04.分页查询.html">
            
                
                    <a href="../day15/04.分页查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="day15/05.聚合函数.html">
            
                
                    <a href="../day15/05.聚合函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        聚合函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="day15/06.分组.html">
            
                
                    <a href="../day15/06.分组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        分组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="day15/07.连接.html">
            
                
                    <a href="../day15/07.连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="day15/08.自连接.html">
            
                
                    <a href="../day15/08.自连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="day15/09.子查询.html">
            
                
                    <a href="../day15/09.子查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        子查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="day15/10.总结.html">
            
                
                    <a href="../day15/10.总结.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="day16/readme.html">
            
                
                    <a href="../day16/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        MYSQL数据库编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="day16/data.html">
            
                
                    <a href="../day16/data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        数据准备
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="day16/sql_code.html">
            
                
                    <a href="../day16/sql_code.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        SQL演练
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="day16/dbdesign.html">
            
                
                    <a href="../day16/dbdesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="day16/pymysql.html">
            
                
                    <a href="../day16/pymysql.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        数据库编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="day16/zongjie.html">
            
                
                    <a href="../day16/zongjie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="day17/00.readme.html">
            
                
                    <a href="../day17/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        MySQL数据库高级用法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="day17/01.view.html">
            
                
                    <a href="../day17/01.view.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="day17/02.transaction.html">
            
                
                    <a href="../day17/02.transaction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        事务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="day17/03.sql_index.html">
            
                
                    <a href="../day17/03.sql_index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="day17/04.user.html">
            
                
                    <a href="../day17/04.user.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        用户管理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="day17/05.master_slave.html">
            
                
                    <a href="../day17/05.master_slave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        主从配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="day17/06.review.html">
            
                
                    <a href="../day17/06.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="day18/00.readme.html">
            
                
                    <a href="../day18/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        miniweb框架
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="day18/01.框架是什么.html">
            
                
                    <a href="../day18/01.框架是什么.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        框架概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="day18/02.实现框架.html">
            
                
                    <a href="../day18/02.实现框架.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        实现一个简单的框架
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="day18/03.模板.html">
            
                
                    <a href="../day18/03.模板.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        模板替换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="day18/04.路由.html">
            
                
                    <a href="../day18/04.路由.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        路由概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="day18/05.显示股票数据.html">
            
                
                    <a href="../day18/05.显示股票数据.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        股票收藏夹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="day18/05.review.html">
            
                
                    <a href="../day18/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        复习
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="3-import&#x5BFC;&#x5165;&#x6A21;&#x5757;">3 import&#x5BFC;&#x5165;&#x6A21;&#x5757;</h1>
<h2 id="31-&#x5B66;&#x4E60;&#x76EE;&#x6807;">3.1 &#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x77E5;&#x9053;&#x5982;&#x4F55;&#x5BFC;&#x5165;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6A21;&#x5757;</li>
<li>&#x80FD;&#x591F;&#x8BF4;&#x51FA;import&#x548C;from-import&#x4E24;&#x79CD;&#x5BFC;&#x5165;&#x65B9;&#x5F0F;&#x7684;&#x533A;&#x522B;</li>
</ul>
<h2 id="32-import&#x641C;&#x7D22;&#x8DEF;&#x5F84;">3.2 import&#x641C;&#x7D22;&#x8DEF;&#x5F84;</h2>
<h3 id="321-&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x4E86;&#x89E3;import&#x7684;&#x641C;&#x7D22;&#x8DEF;&#x5F84;">3.2.1 &#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x4E86;&#x89E3;import&#x7684;&#x641C;&#x7D22;&#x8DEF;&#x5F84;</h3>
<pre><code>&#x5927;&#x5BB6;&#x8BD5;&#x60F3;&#x4E00;&#x4E0B; &#x5728;&#x5DE5;&#x4F5C;&#x4E2D;&#x4ECA;&#x5E74;&#x5728;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#x4E2D;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x5165;&#x67D0;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#xFF0C;&#x90A3;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x600E;&#x4E48;&#x6837;&#x624D;&#x80FD;&#x8BA9;Python&#x89E3;&#x91CA;&#x5668;&#x80FD;&#x591F;&#x627E;&#x5230;&#x8BE5;&#x6A21;&#x5757;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#x5462;?
- &#x5C06;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x62F7;&#x8D1D;&#x4E00;&#x4EFD;&#x5230;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x76EE;&#x5F55;&#x4E0B; &#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x8BA9;&#x6A21;&#x5757;&#x592A;&#x5197;&#x4F59;
- &#x5C06;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x6240;&#x5728;&#x8DEF;&#x5F84;&#x76F4;&#x63A5;&#x544A;&#x8BC9;Python&#x89E3;&#x91CA;&#x5668; &#x8BA9;Python&#x89E3;&#x91CA;&#x5668;&#x80FD;&#x591F;&#x641C;&#x7D22;&#x5230;&#x8FD9;&#x4E2A;&#x6A21;&#x5757; &#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;&#x7075;&#x6D3B;&#x3002;

&#x5982;&#x679C;&#x60F3;&#x8981;&#x544A;&#x8BC9;Python&#x89E3;&#x91CA;&#x5668; &#x67D0;&#x67D0;&#x6A21;&#x5757;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5148;&#x77E5;&#x9053;&#x4ED6;&#x662F;&#x6839;&#x636E;&#x4EC0;&#x4E48;&#x6765;&#x67E5;&#x627E;&#x6A21;&#x5757;&#x7684;? 
</code></pre><p><img src="../assets/day12/01sys_path.png" alt=""></p>
<blockquote>
<p>&#x8DEF;&#x5F84;&#x8BF4;&#x660E;</p>
</blockquote>
<ul>
<li>&#x4ECE;&#x4E0A;&#x9762;&#x5217;&#x51FA;&#x7684;&#x76EE;&#x5F55;&#x91CC;&#x4F9D;&#x6B21;&#x67E5;&#x627E;&#x8981;&#x5BFC;&#x5165;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;</li>
<li>&apos;&apos; &#x8868;&#x793A;&#x5F53;&#x524D;&#x8DEF;&#x5F84;</li>
<li>&#x5217;&#x8868;&#x4E2D;&#x7684;&#x8DEF;&#x5F84;&#x7684;&#x5148;&#x540E;&#x987A;&#x5E8F;&#x4EE3;&#x8868;&#x4E86;python&#x89E3;&#x91CA;&#x5668;&#x5728;&#x641C;&#x7D22;&#x6A21;&#x5757;&#x65F6;&#x7684;&#x5148;&#x540E;&#x987A;&#x5E8F;</li>
</ul>
<h3 id="322-&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x65F6;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x6A21;&#x5757;&#x8DEF;&#x5F84;">3.2.2 &#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x65F6;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x6A21;&#x5757;&#x8DEF;&#x5F84;</h3>
<pre><code class="lang-python">sys.path.append(<span class="hljs-string">&apos;/home/itcast/xxx&apos;</span>)
sys.path.insert(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;/home/itcast/xxx&apos;</span>)  <span class="hljs-comment"># &#x53EF;&#x4EE5;&#x786E;&#x4FDD;&#x5148;&#x641C;&#x7D22;&#x8FD9;&#x4E2A;&#x8DEF;&#x5F84;</span>
</code></pre>
<pre><code class="lang-python">In [<span class="hljs-number">37</span>]: sys.path.insert(<span class="hljs-number">0</span>,<span class="hljs-string">&quot;/home/python/xxxx&quot;</span>)
In [<span class="hljs-number">38</span>]: sys.path
Out[<span class="hljs-number">38</span>]: 
[<span class="hljs-string">&apos;/home/python/xxxx&apos;</span>,
 <span class="hljs-string">&apos;&apos;</span>,
 <span class="hljs-string">&apos;/usr/bin&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python35.zip&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python3.5&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python3.5/plat-x86_64-linux-gnu&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python3.5/lib-dynload&apos;</span>,
 <span class="hljs-string">&apos;/usr/local/lib/python3.5/dist-packages&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python3/dist-packages&apos;</span>,
 <span class="hljs-string">&apos;/usr/lib/python3/dist-packages/IPython/extensions&apos;</span>,
 <span class="hljs-string">&apos;/home/python/.ipython&apos;</span>]
</code></pre>
<h2 id="33-&#x91CD;&#x65B0;&#x5BFC;&#x5165;&#x6A21;&#x5757;">3.3 &#x91CD;&#x65B0;&#x5BFC;&#x5165;&#x6A21;&#x5757;</h2>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x5BFC;&#x5165;&#x6A21;&#x5757; 
    &#x6A21;&#x5757;&#x88AB;&#x5BFC;&#x5165;&#x540E;&#xFF0C;<code>import module</code>&#x4E0D;&#x80FD;&#x91CD;&#x65B0;&#x5BFC;&#x5165;&#x6A21;&#x5757;&#xFF0C;&#x91CD;&#x65B0;&#x5BFC;&#x5165;&#x9700;&#x7528;<code>reload</code>&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x521B;&#x5EFA;&#x6A21;&#x5757;&#x5BF9;&#x8C61;</p>
</blockquote>
<p><img src="../assets/day12/QQ20171023-213646@2x.png" alt=""></p>
<p><img src="../assets/day12/QQ20171023-213753@2x.png" alt=""></p>
<p><img src="../assets/day12/QQ20171023-214117@2x.png" alt=""></p>
<p><img src="../assets/day12/QQ20171023-214038@2x.png" alt=""></p>
<h2 id="34-&#x591A;&#x6A21;&#x5757;&#x5F00;&#x53D1;&#x65F6;&#x7684;&#x6CE8;&#x610F;&#x70B9;">3.4 &#x591A;&#x6A21;&#x5757;&#x5F00;&#x53D1;&#x65F6;&#x7684;&#x6CE8;&#x610F;&#x70B9;</h2>
<p><code>recv_msg.py&#x6A21;&#x5757;</code></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> common <span class="hljs-keyword">import</span> RECV_DATA_LIST
<span class="hljs-comment"># from common import HANDLE_FLAG</span>
<span class="hljs-keyword">import</span> common


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">recv_msg</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x6A21;&#x62DF;&#x63A5;&#x6536;&#x5230;&#x6570;&#x636E;&#xFF0C;&#x7136;&#x540E;&#x6DFB;&#x52A0;&#x5230;common&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x5217;&#x8868;&#x4E2D;&quot;&quot;&quot;</span>
    print(<span class="hljs-string">&quot;---&gt;recv_msg&quot;</span>)
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
        RECV_DATA_LIST.append(i)


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_recv_data</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x6D4B;&#x8BD5;&#x63A5;&#x6536;&#x5230;&#x7684;&#x6570;&#x636E;&quot;&quot;&quot;</span>
    print(<span class="hljs-string">&quot;---&gt;test_recv_data&quot;</span>)
    print(RECV_DATA_LIST)


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">recv_msg_next</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x518D;&#x63A5;&#x6536;&#x53E6;&#x5916;&#x7684;&#x5176;&#x4ED6;&#x6570;&#x636E;&quot;&quot;&quot;</span>
    print(<span class="hljs-string">&quot;---&gt;recv_msg_next&quot;</span>)
    <span class="hljs-comment"># if HANDLE_FLAG:</span>
    <span class="hljs-keyword">if</span> common.HANDLE_FLAG:
        print(<span class="hljs-string">&quot;------&#x53D1;&#x73B0;&#x4E4B;&#x524D;&#x7684;&#x6570;&#x636E;&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x5B8C;&#x6210;&#xFF0C;&#x8FD9;&#x91CC;&#x8FDB;&#x884C;&#x63A5;&#x6536;&#x5176;&#x4ED6;&#x7684;&#x6570;&#x636E;(&#x6A21;&#x62DF;&#x8FC7;&#x7A0B;...)----&quot;</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">&quot;------&#x53D1;&#x73B0;&#x4E4B;&#x524D;&#x7684;&#x6570;&#x636E;&#x672A;&#x5904;&#x7406;&#x5B8C;&#xFF0C;&#x7B49;&#x5F85;&#x4E2D;....------&quot;</span>)
</code></pre>
<p><code>handle_msg.py&#x6A21;&#x5757;</code></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> common <span class="hljs-keyword">import</span> RECV_DATA_LIST
<span class="hljs-comment"># from common import HANDLE_FLAG</span>
<span class="hljs-keyword">import</span> common

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">handle_data</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x6A21;&#x62DF;&#x5904;&#x7406;recv_msg&#x6A21;&#x5757;&#x63A5;&#x6536;&#x7684;&#x6570;&#x636E;&quot;&quot;&quot;</span>
    print(<span class="hljs-string">&quot;---&gt;handle_data&quot;</span>)
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> RECV_DATA_LIST:
        print(i)

    <span class="hljs-comment"># &#x65E2;&#x7136;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x4E86;&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x53D8;&#x91CF;HANDLE_FLAG&#x8BBE;&#x7F6E;&#x4E3A;True&#xFF0C;&#x610F;&#x5473;&#x7740;&#x5904;&#x7406;&#x5B8C;&#x6210;</span>
    <span class="hljs-comment"># global HANDLE_FLAG</span>
    <span class="hljs-comment"># HANDLE_FLAG = True</span>
    common.HANDLE_FLAG = <span class="hljs-keyword">True</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_handle_data</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x6D4B;&#x8BD5;&#x5904;&#x7406;&#x662F;&#x5426;&#x5B8C;&#x6210;&#xFF0C;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x4E3A;True&quot;&quot;&quot;</span>
    print(<span class="hljs-string">&quot;---&gt;test_handle_data&quot;</span>)
    <span class="hljs-comment"># if HANDLE_FLAG:</span>
    <span class="hljs-keyword">if</span> common.HANDLE_FLAG:
        print(<span class="hljs-string">&quot;=====&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x5B8C;&#x6210;====&quot;</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">&quot;=====&#x672A;&#x5904;&#x7406;&#x5B8C;&#x6210;====&quot;</span>)
</code></pre>
<p><code>main.py&#x6A21;&#x5757;</code></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> recv_msg <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">from</span> handle_msg <span class="hljs-keyword">import</span> *


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment"># 1. &#x63A5;&#x6536;&#x6570;&#x636E;</span>
    recv_msg()
    <span class="hljs-comment"># 2. &#x6D4B;&#x8BD5;&#x662F;&#x5426;&#x63A5;&#x6536;&#x5B8C;&#x6BD5;</span>
    test_recv_data()
    <span class="hljs-comment"># 3. &#x5224;&#x65AD;&#x5982;&#x679C;&#x5904;&#x7406;&#x5B8C;&#x6210;&#xFF0C;&#x5219;&#x63A5;&#x6536;&#x5176;&#x5B83;&#x6570;&#x636E;</span>
    recv_msg_next()
    <span class="hljs-comment"># 4. &#x5904;&#x7406;&#x6570;&#x636E;</span>
    handle_data()
    <span class="hljs-comment"># 5. &#x6D4B;&#x8BD5;&#x662F;&#x5426;&#x5904;&#x7406;&#x5B8C;&#x6BD5;</span>
    test_handle_data()
    <span class="hljs-comment"># 6. &#x5224;&#x65AD;&#x5982;&#x679C;&#x5904;&#x7406;&#x5B8C;&#x6210;&#xFF0C;&#x5219;&#x63A5;&#x6536;&#x5176;&#x5B83;&#x6570;&#x636E;</span>
    recv_msg_next()


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
    main()
</code></pre>
<p><img src="../assets/day12/QQ20171024-080610@2x.png" alt=""><br><img src="../assets/day12/QQ20171024-081134@2x.png" alt=""></p>
<h2 id="35-&#x603B;&#x7ED3;">3.5 &#x603B;&#x7ED3;</h2>
<ul>
<li><p>&#x5BFC;&#x5165;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6A21;&#x5757;&#x7684;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;</p>
<ul>
<li>&#x5C06;&#x6A21;&#x5757;&#x6240;&#x5728;&#x8DEF;&#x5F84;&#x518D;&#x7A0B;&#x5E8F;&#x4E2D;&#x6DFB;&#x52A0;&#x5230;sys.path&#x5217;&#x8868;&#x4E2D; 
&#x8BE5;&#x65B9;&#x6CD5;&#x7075;&#x6D3B;&#xFF0C;&#x4F46;&#x662F;&#x7A0B;&#x5E8F;&#x91CD;&#x542F;&#x540E;&#x8FD8;&#x9700;&#x8981;&#x518D;&#x6B21; &#x6DFB;&#x52A0;&#x5217;&#x8868;</li>
</ul>
<ul>
<li>&#x4FEE;&#x6539;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;PYTHONPATH&#x73AF;&#x5883;&#x53D8;&#x91CF; 
  export PYTHONPATH=$PYTHONPATH:&#x8DEF;&#x5F84;</li>
</ul>
</li>
<li><p>import&#x548C;from-import&#x7684;&#x663E;&#x8457;&#x533A;&#x522B;</p>
<ul>
<li><p>from A import B&#x5728;&#x5BFC;&#x5165;&#x8FC7;&#x7A0B;&#x4E2D; &#x521B;&#x5EFA;&#x6A21;&#x5757;&#x5BF9;&#x8C61; &#x5C06;&#x6A21;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;B&#x7684;&#x5F15;&#x7528;&#x4FDD;&#x5B58;&#x5728;&#x672C;&#x5730;&#x4F5C;&#x7528;&#x57DF;, &#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x6709;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x53EB;B&#x7684;&#x5BF9;&#x8C61;,locals()&#x53EF;&#x4EE5;&#x67E5;&#x770B;;</p>
<p>import A &#x5728;&#x5BFC;&#x5165;&#x6A21;&#x5757;&#x7684;&#x8FC7;&#x7A0B; &#x521B;&#x5EFA;&#x6A21;&#x5757;&#x5BF9;&#x8C61; &#x5C06;&#x6A21;&#x5757;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x4FDD;&#x5B58;&#x5728;&#x672C;&#x5730;</p>
</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../day11/02.copy.html" class="navigation navigation-prev " aria-label="Previous page: 赋值-浅拷贝-深拷贝"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../day11/04.review.html" class="navigation navigation-next " aria-label="Next page: 总结"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python高级 -->
</html>
